package com.hb.trans.mvp.ui.activity


import android.os.Bundle
import com.google.android.material.tabs.TabLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import android.view.MenuItem
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.basiclib.base.BaseActivity
import com.hb.trans.R
import com.hb.trans.global.ACTIVITY_CAR_DETAIL
import com.hb.trans.mvp.presenter.NewDetailPresenter
import com.hb.trans.mvp.ui.fragment.SchoolInfoItemFragment
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_car_detail.*
import javax.inject.Inject


@Route(path = ACTIVITY_CAR_DETAIL)
class CarDetailActivity : BaseActivity() {
    @Inject
    override fun getContentViewResId(): Int = R.layout.activity_car_detail

    override fun onActivityInject() {
        AndroidInjection.inject(this)
    }

    override fun attachView(savedInstanceState: Bundle?) {
        ARouter.getInstance().inject(this)
    }

    override fun getPresenter(): NewDetailPresenter? = null

    override fun initView() {
        setSupportActionBar(carDetailToolbar.toolbar)
        supportActionBar!!.setDisplayHomeAsUpEnabled(true)
        supportActionBar!!.setHomeAsUpIndicator(R.mipmap.ic_left_arrow)
        initTab()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> onBackPressed()
        }
        return true
    }

    override fun initData() {
    }

    override fun setListener() {
    }

    private fun initTab() {
        var mTitle = listOf("基础资料信息", "车载计时终端绑定信息")

        var fragment1 = SchoolInfoItemFragment()

        var fragment2 = SchoolInfoItemFragment()



        var mFragment = listOf(
            fragment1, fragment2
        )
        carDetailTabLayout.addTab(carDetailTabLayout.newTab().setText(mTitle[0]))
        carDetailTabLayout.addTab(carDetailTabLayout.newTab().setText(mTitle[1]))
        carDetailTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                //选中Tab
            }

            override fun onTabUnselected(tab: TabLayout.Tab) {
                //未选中Tab
            }

            override fun onTabReselected(tab: TabLayout.Tab) {
                //再次选中
            }
        })

        carDetailViewPager.adapter = object :
            androidx.fragment.app.FragmentPagerAdapter(supportFragmentManager) {
            override fun getItem(position: Int): androidx.fragment.app.Fragment {
                return mFragment[position]
            }

            override fun getCount(): Int {
                return mFragment.size
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return mTitle[position]
            }
        }
        carDetailTabLayout.setupWithViewPager(carDetailViewPager)
//        carDetailTabLayout.getTabAt(1)!!.select()

    }
}
